package com.bjpowernode.controller;

import com.bjpowernode.service.ReviewService;
import com.bjpowernode.user.Review;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Date;

@Controller
@RequestMapping(value = "review")
public class ReviewController {

    @Resource
    private ReviewService reviewService;

    @RequestMapping(value = "/add.do",produces = "application/text;charset=utf-8")
    @ResponseBody
    public String addReview(@RequestParam("username") String username,@RequestParam("review") String reviewString,@RequestParam("zpId") Integer reId){
        Review review = new Review();
        review.setUsername(username);
        review.setZpneirong(reviewString);
        review.setZpid(reId);
        String time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
        review.setZptime(time);
        int res = reviewService.addReview(review);
        return res == 1 ? "回复成功" : "回复失败";
    }
}
